< previous page page_282 next page >

Page 282
are selecting, SQL does not require you to use the table.column syntax. But it is a good habit to do so, especially when you are building SQL statements in Visual Basic code.
You should also notice that the WHERE clause comparison columns (Publishers.PubID and Titles.PubID) were not included in the SELECT portion of the statement. You do not have to include the column in the SELECT portion of the statement to use it in the WHERE portion of the statement, as long as the column already exists in the underlying table.
Combining tables using the WHERE clause always returns a nonupdateable result set. You cannot update the columns in a view created in this manner. If you want to link tables together and also be able to update the underlying tables for that view, you need to use the JOIN clause, which is covered later today.
You can combine the link-type and limit-type versions of the WHERE clause in a single SQL SELECT_FROM statement. Execute the following statement and compare your results to those in Figure 8.12.
SELECT Titles.PubID,Titles.Title,Publishers.Name
   FROM Titles, Publishers
   WHERE Titles.PubID = Publishers.PubID
      AND Publishers.PubID BETWEEN 5 AND 10
0282-01.jpg
Figure 8.12.
Combining link-type and limit-type 
WHERE clauses.
The preceding SQL statement selects only those records in which the PubID columns match and the PubID values are between 5 and 10.
You can use the WHERE clause to link more than two data tables. The linking column for table1 and table2 does not have to be the same column for table2 and table3. Execute the following statement and review your results against those in Figure 8.13.
SELECT Titles.PubID,Titles.Title,Publishers.Name,Authors.Name
   FROM Titles, Publishers,Authors
   WHERE Titles.PubID = Publishers.PubID
      AND Titles.AUID = Authors.AUID

 
< previous page page_282 next page >

If you like this book, buy it!